home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / snip9503 / cmdline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-14  |  687 b   |  30 lines

  1. /*
  2. **  CMDLINE.C - Demonstrates accessing command line arguments
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #define plural_text(n) &"s"[(1 == (n))]
  9. #define plural_text2(n) &"es"[(1 == (n)) << 1]
  10.  
  11. main(int argc, char *argv[])
  12. {
  13.       int i, n = argc - 1;
  14.  
  15.       printf("You passed %d argument%s on the command line.",
  16.             n, plural_text(n));
  17.  
  18.       if (argc > 1)
  19.       {
  20.             puts(" They are:");
  21.             for (i = 1; i < argc; ++i)
  22.             {
  23.                   printf("\nArgument #%d:\n  Text: \"%s\"\n  Value: %d\n",
  24.                         i, argv[i], atoi(argv[i]));
  25.             }
  26.       }
  27.       else  putchar('\n');
  28.       return 0;
  29. }
  30.